New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

unist-util-assert

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-assert

Assert Unist nodes

  • 1.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
390
decreased by-18.24%
Maintainers
1
Weekly downloads
 
Created
Source

unist-util-assert

Build Coverage Downloads Size Sponsors Backers Chat

unist utility to assert trees.

Install

npm:

npm install unist-util-assert

Usage

var assert = require('unist-util-assert')

assert({type: 'root', children: []})
assert({type: 'break'})
assert({type: 'element', properties: {}, children: []})
// All OK.

assert({children: []})
// AssertionError: node should have a type: `{ children: [] }`

assert.parent({type: 'break'})
// AssertionError: parent should have `children`: `{ type: 'break' }`

assert({type: 'element', properties: function() {}})
// AssertionError: non-specced property `properties` should be JSON: `{ type: 'element', properties: [Function] }`

assert.void({type: 'text', value: 'Alpha'})
// AssertionError: void should not have `value`: `{ type: 'text', value: 'Alpha' }`

assert({type: 'paragraph', children: ['foo']})
// AssertionError: node should be an object: `'foo'` in `{ type: 'paragraph', children: [ 'foo' ] }`

API

assert(tree)

Assert that tree is a valid unist node. If tree is a parent, all children will be asserted as well.

assert.parent(tree)

Assert that tree is a valid unist parent. All children will be asserted as well.

assert.text(node)

Assert that node is a valid unist literal.

assert.void(node)

Assert that node is a valid unist node, but neither parent nor literal.

Extensions

This module can be used as a base to test subsets of unist (for an example, see mdast-util-assert). All functions that are exposed from such a module, and functions used internally to test children, should be wrapped in assert.wrap, which adds an inspectable string of the respective node, and its parent when available, to the exposed error message.

assert.wrap(fn)

Wraps fn (which is passed a node, and an optional parent node), so that any errors thrown inside it will contain information regarding the node (and the parent, when given).

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 22 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc